import 'package:flutter/material.dart';
import 'package:xiecheng_lvyou/model/common_model.dart';
import 'package:xiecheng_lvyou/util/navigator_util.dart';
import 'package:xiecheng_lvyou/widget/webview.dart';

class LocalNav extends StatelessWidget {
// StatelessWidget里面的属性都是不可变的

  final List<CommonModel>? localNavList;

  const LocalNav({super.key, @required this.localNavList});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 64,
      decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(6))),
      child: Padding(
        padding: const EdgeInsets.all(7),
        child: _items(context),
      ),
    );
  }

  _items(BuildContext context) {
    if (localNavList == null) return null;
    List<Widget> items = [];
    localNavList?.forEach((model) {
      items.add(_item(context, model));
    });
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: items,
    );
  }

  // 创建单个Widget
  Widget _item(BuildContext context, CommonModel model) {
    return GestureDetector(
      onTap: () {
        NavigatorUtil.push(
            context,
            WebView(
                url: model.url,
                statusBarColor: model.statusBarColor,
                hideAppBar: model.hideAppBar));
      },
      child: Column(
        children: <Widget>[
          Image.network(
            model.icon ?? '',
            width: 32,
            height: 32,
          ),
          Text(
            model.title ?? '',
            style: const TextStyle(fontSize: 12),
          )
        ],
      ),
    );
  }
}
